
ENT.Type = "anim"
ENT.Base = "base_gmodentity"

ENT.PrintName = "Speaker"
ENT.Author = "[GU]|ZLC|thomasfn"
ENT.Contact = "Don't."
ENT.Instructions = "Spawn it."
ENT.Purpose = ""

ENT.Spawnable = false
ENT.AdminSpawnable = false

ENT.ItemModel = "models/GraffitiRTST/creative_woofer.mdl"
util.PrecacheModel( ENT.ItemModel )

ENT.IsSpeaker = true

if (SERVER) then

	AddCSLuaFile( "shared.lua" )
	
	ENT.NextUse = CurTime()
	ENT.PrintTimer = 7

	function ENT:Initialize()
		self.Entity:SetModel(self.ItemModel)
		self.Entity:PhysicsInit(SOLID_VPHYSICS)
		self.Entity:SetMoveType(MOVETYPE_VPHYSICS)
		self.Entity:SetSolid(SOLID_VPHYSICS)
		
		if (!self.Data) then self.Data = {} end
		if (!self.Data[self:EntIndex()]) then self.Data[self:EntIndex()] = {} end
		self.Data[self:EntIndex()].SoundName = "None"

		local phys = self.Entity:GetPhysicsObject()
		if (phys && phys:IsValid()) then phys:Wake() end
		
		PCBeam:ResetEntity()
	end
	
	function ENT:Use( activator, ply )
		if (CurTime() < self.NextUse) then return end
		self.NextUse = CurTime()+1
	end
	
	function ENT:Sound_Play( soundname )
		if (self.Data[self:EntIndex()].Playing) then self:Sound_Stop() end
		self.Data[self:EntIndex()].Playing = true
		PCBeam:SetValue( self, "Playing", true )
		self.Data[self:EntIndex()].SND = CreateSound( self.Entity, Sound(soundname) );
		self.Data[self:EntIndex()].SND:Play()
		self.Data[self:EntIndex()].SoundName = soundname
	end
	
	function ENT:Sound_Stop()
		if (!self.Data[self:EntIndex()].Playing) then return end
		PCBeam:SetValue( self, "Playing", false )
		if (!self.Data[self:EntIndex()].SND) then return end
		self.Data[self:EntIndex()].SND:Stop()
		self.Data[self:EntIndex()].SND = nil
		self.Data[self:EntIndex()].SoundName = "None"
	end
	
	function ENT:Sound_Get()
		return self.Data[self:EntIndex()].SoundName
	end
	
	function ENT:OnRemove()
		self:Sound_Stop()
		PCBeam:ResetEntity( self )
	end
	
end

if (CLIENT) then

	function ENT:Draw()
		// Draw our entity
		self.BaseClass.Draw( self )

	end
	
end